package calao.client.ui;

import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.FlowPanel;

public class FlexibleText
extends Composite
{
	
	public final static String STYLE = "calao-FlexibleText";
	
	FlowPanel content = new FlowPanel();
	
	public FlexibleText()
	{
		initWidget(content);
		addStyleName(STYLE);
	}
	
	public void setText(String text)
	{
		content.clear();
		int start = 0;
		while (start<text.length()) {
			switch (text.charAt(start)) {
			case ' ':
			case '\r':
				start++;
				continue;
			}
			int end = text.indexOf('\n', start);
			if (end==-1) end = text.length();
			if (end>(start+1)) addParagraph(text.substring(start, end));
			start = end+1;
		}
	}
	
	public void addParagraph(String text)
	{
		content.add(new Paragraph(text));
	}

}
